﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="StoreManage.aspx.cs" Inherits="StoreManage" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        var updateRecord = function (form) {
            if (form.record == null) {
                return;
            }

            if (!form.getForm().isValid()) {
                Ext.net.Notification.show({
                    iconCls: "icon-exclamation",
                    html: "Form is invalid",
                    title: "Error"
                });
                return false;
            }

            form.getForm().updateRecord(form.record);
        };

        var addRecord = function (form, grid) {
            if (!form.getForm().isValid()) {
                Ext.net.Notification.show({
                    iconCls: "icon-exclamation",
                    html: "Form is invalid",
                    title: "Error"
                });

                return false;
            }

            grid.insertRecord(0, form.getForm().getFieldValues(false, "dataIndex"));
            form.getForm().reset();
        };
    </script>
</head>
<body>
    <ext:ResourceManager ID="ResourceManager1" runat="server" />
    <form id="form1" runat="server">
    <div>
 
        
      
        <ext:Store 
            ID="Store1" 
            runat="server" 
            AutoSave="true" 
            ShowWarningOnFailure="false"
            OnBeforeStoreChanged="HandleChanges" 
            SkipIdForNewRecords="false"
            RefreshAfterSaving="None">
            <Reader>
                <ext:JsonReader IDProperty="id">
                    <Fields>
                        <ext:RecordField Name="id" />
                        <ext:RecordField Name="Store" AllowBlank="false" />
                        <ext:RecordField Name="Logo" AllowBlank="false" /> 
                        <ext:RecordField Name="Returns" AllowBlank="true" /> 
                        <ext:RecordField Name="Shipping" AllowBlank="true" /> 
                        <ext:RecordField Name="Payment" AllowBlank="true" /> 
                        <ext:RecordField Name="Replies" AllowBlank="true" /> 
                        <ext:RecordField Name="Feedback" AllowBlank="true" /> 
                        <ext:RecordField Name="FAQ" AllowBlank="true" /> 
                    </Fields>
                </ext:JsonReader>
            </Reader>
            
            <Listeners>
                <Exception Handler="
                    Ext.net.Notification.show({
                        iconCls    : 'icon-exclamation', 
                        html       : e.message, 
                        title      : 'EXCEPTION', 
                        autoScroll : true, 
                        hideDelay  : 5000, 
                        width      : 300, 
                        height     : 200
                    });" />
                <BeforeSave Handler="var valid = true; this.each(function(r){if(r.dirty && !r.isValid()){valid=false;}}); return valid;" />
            </Listeners>
        </ext:Store>
        
        <ext:Hidden ID="UseConfirmation" runat="server" Text="false" />
        
        <ext:FormPanel 
            ID="UserForm" 
            runat="server"
            Icon="User"
            Frame="true"
            LabelAlign="Right"
            Title="User -- All fields are required"
            Width="500">
            <Items>
                <ext:TextField ID="TextField1" runat="server"
                    FieldLabel="Store"
                    DataIndex="Store"
                    AllowBlank="false"
                    
                    AnchorHorizontal="100%"
                    />
                
                <ext:TextField ID="TextField2" runat="server"
                    FieldLabel="Logo"
                    DataIndex="Logo"
                    AllowBlank="false"
                    AnchorHorizontal="100%"
                    />
                      <ext:TextField ID="TextField3" runat="server"
                    FieldLabel="Returns"
                    DataIndex="Returns"
                    AllowBlank="true"
                    AnchorHorizontal="100%"
                    />      <ext:TextField ID="TextField6" runat="server"
                    FieldLabel="Shipping"
                    DataIndex="Shipping"
                    AllowBlank="true"
                    AnchorHorizontal="100%"
                    />      <ext:TextField ID="TextField7" runat="server"
                    FieldLabel="Payment"
                    DataIndex="Payment"
                    AllowBlank="true"
                    AnchorHorizontal="100%"
                    />      <ext:TextField ID="TextField8" runat="server"
                    FieldLabel="Replies"
                    DataIndex="Replies"
                    AllowBlank="true"
                    AnchorHorizontal="100%"
                    />      <ext:TextField ID="TextField9" runat="server"
                    FieldLabel="Feedback"
                    DataIndex="Feedback"
                    AllowBlank="true"
                    AnchorHorizontal="100%"
                    />      <ext:TextField ID="TextField10" runat="server"
                    FieldLabel="FAQ"
                    DataIndex="FAQ"
                    AllowBlank="true"
                    AnchorHorizontal="100%"
                    />
            </Items>
            
            <Buttons>
                <ext:Button ID="Button1" 
                    runat="server"
                    Text="Save"
                    Icon="Disk">
                    <Listeners>
                        <Click Handler="updateRecord(#{UserForm});" />
                    </Listeners>
                </ext:Button>
                
                <ext:Button ID="Button2" 
                    runat="server"
                    Text="Create"
                    Icon="UserAdd">
                    <Listeners>
                        <Click Handler="addRecord(#{UserForm}, #{GridPanel1});" />
                    </Listeners>
                </ext:Button>
                
                <ext:Button ID="Button3" 
                    runat="server"
                    Text="Reset">
                    <Listeners>
                        <Click Handler="#{UserForm}.getForm().reset();" />
                    </Listeners>
                </ext:Button>
            </Buttons>
        </ext:FormPanel>
        
        <ext:GridPanel 
            ID="GridPanel1" 
            runat="server"
            Icon="Table"
            Frame="true"
            Title="Users"
            Height="400"
            Width="500"
            StoreID="Store1"
            StyleSpec="margin-top: 10px">
            <ColumnModel>
                <Columns>
                    <ext:Column Header="ID" Width="40" DataIndex="id" />
                    
                    <ext:Column Header="Store" Width="100" DataIndex="Store">
                        <Editor>
                            <ext:TextField ID="TextField4" runat="server" />    
                        </Editor>
                    </ext:Column>
                    
                    <ext:Column Header="Logo" Width="50" DataIndex="Logo">
                        <Editor>
                            <ext:TextField ID="TextField5" runat="server" />    
                        </Editor>
                    </ext:Column><ext:Column Header="Returns" Width="50" DataIndex="Returns">
                        <Editor>
                            <ext:TextField ID="TextField11" runat="server" />    
                        </Editor>
                    </ext:Column><ext:Column Header="Shipping" Width="50" DataIndex="Shipping">
                        <Editor>
                            <ext:TextField ID="TextField12" runat="server" />    
                        </Editor>
                    </ext:Column><ext:Column Header="Payment" Width="50" DataIndex="Payment">
                        <Editor>
                            <ext:TextField ID="TextField13" runat="server" />    
                        </Editor>
                    </ext:Column><ext:Column Header="Replies" Width="50" DataIndex="Replies">
                        <Editor>
                            <ext:TextField ID="TextField14" runat="server" />    
                        </Editor>
                    </ext:Column><ext:Column Header="Feedback" Width="50" DataIndex="Feedback">
                        <Editor>
                            <ext:TextField ID="TextField15" runat="server" />    
                        </Editor>
                    </ext:Column><ext:Column Header="FAQ" Width="50" DataIndex="FAQ">
                        <Editor>
                            <ext:TextField ID="TextField16" runat="server" />    
                        </Editor>
                    </ext:Column>
                    
                 
                    
                    <ext:CommandColumn Width="40">
                        <Commands>
                            <ext:GridCommand Text="Reject" ToolTip-Text="Reject row changes" CommandName="reject" Icon="ArrowUndo" />
                        </Commands>
                        <PrepareToolbar Handler="toolbar.items.get(0).setVisible(record.dirty);" />
                    </ext:CommandColumn>
                </Columns>
            </ColumnModel>
            
            <Listeners>
                <Command Handler="record.reject();" />
            </Listeners>
            
            <View>
                <ext:GridView ID="GridView1" runat="server" ForceFit="true" />
            </View>
            
            <TopBar>
                <ext:Toolbar ID="Toolbar1" runat="server">
                    <Items>
                        <ext:Button ID="Button4" runat="server" Text="Add" Icon="Add">
                            <Listeners>
                                <Click Handler="#{GridPanel1}.insertRecord();" />
                            </Listeners>
                        </ext:Button>
                        
                        <ext:Button ID="Button5" runat="server" Text="Delete" Icon="Exclamation">
                            <Listeners>
                                 <Click Handler="if( confirm('r u sure del')){#{GridPanel1}.deleteSelected();#{UserForm}.getForm().reset();}" />
                         </Listeners>
                        </ext:Button>
                        
                        <ext:ToolbarSeparator />
                        
                        <ext:Button ID="Button6" 
                            runat="server" 
                            Text="Auto Save"
                            EnableToggle="true"
                            Pressed="true"
                            ToolTip="When enabled, Store will execute Ajax requests as soon as a Record becomes dirty.">
                            <Listeners>
                                <Toggle Handler="#{Store1}.autoSave = pressed;#{Store1}.useIdConfirmation = !pressed;#{UseConfirmation}.setValue(!pressed);" />
                            </Listeners>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </TopBar>
            
            <SelectionModel>
                <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true">
                    <Listeners>
                        <RowSelect Handler="#{UserForm}.getForm().loadRecord(record);#{UserForm}.record = record;" />
                    </Listeners>
                </ext:RowSelectionModel>
            </SelectionModel>
            
            <Buttons>
                <ext:Button ID="Button7" runat="server" Text="Save" Icon="Disk">
                    <Listeners>
                        <Click Handler="#{GridPanel1}.save();" />
                    </Listeners>
                </ext:Button>
            </Buttons>
        </ext:GridPanel>
    </div>
    </form>
</body>
</html>
